package com.yanqu.road.server.manger.maidian.house;

import com.yanqu.road.entity.config.player.HouseInfo;
import com.yanqu.road.entity.config.skill.SkillInfo;
import com.yanqu.road.entity.config.skin.SkinInfo;
import com.yanqu.road.entity.player.UserSkin;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.HouseModule;
import com.yanqu.road.server.gameplayer.module.skin.SkinModule;
import com.yanqu.road.server.manger.DataAnalyticsMgr;
import com.yanqu.road.server.manger.config.HouseMgr;
import com.yanqu.road.server.manger.config.SkillMgr;
import com.yanqu.road.server.manger.config.SkinMgr;
import com.yanqu.road.server.manger.maidian.DefaultEventTraceAction;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 钱庄
 */
public class HouseLog {

    public static final String MONEY_BANK = "money_bank";
    public static final String MONEY_BANKLEVEL = "money_banklevel";
    public static final String MONEY_BANKBAR = "money_bankbar";
    public static final String MONEY_BANKLOOK = "money_banklook";

    public static final String MONEY_BANKLV = "money_banklv";
    public static final String MONEY_BANKADD = "money_bankadd";
    public static final String MONEY_BANKNAME = "money_bankname";



    public static void uploadSnapshot(GamePlayer player) {

        try {
            if (!DataAnalyticsMgr.openDataAnalytics()) return;

            DefaultEventTraceAction action = new DefaultEventTraceAction(MONEY_BANK, player);
            //List<Map<String, Object>> objectGroup = new ArrayList<>();

            action.build(MONEY_BANKLEVEL, player.getUserInfo().getHouseLv());

            HouseInfo houseInfo = HouseMgr.getHouseInfo(player.getUserInfo().getHouseLv());
            if(houseInfo != null) {
                List<Integer> list = new ArrayList<>();
                list.add(houseInfo.getBankBarNum());
                list.add(player.getModule(HouseModule.class).getUserHouseBarMap().size());
                action.build(MONEY_BANKBAR, list);
            }

            //外观
            List<Map<String, Object>> objectGroup = new ArrayList<>();
            SkinModule skinModule = player.getModule(SkinModule.class);
            for (Map.Entry<Integer, UserSkin> skinEntry : skinModule.getUserSkinMap().entrySet()) {
                UserSkin userSkin = skinEntry.getValue();
                if(SkinMgr.isBankSkin(userSkin.getSkinId())){
                    //加成
                    Map<String, Object> map = new HashMap<>();
                    SkinInfo skinInfo = SkinMgr.getSkinInfo(userSkin.getSkinId());
                    if(skinInfo != null){
                        int add = 0;
                        for (int skillId : skinInfo.getSkinEffect()) {
                            SkillInfo skillInfo = SkillMgr.getSkillInfo(skillId);
                            if(skillInfo != null){
                                add += SkillMgr.getSkillAddition(skillInfo, userSkin.getLevel());
                            }
                        }
                        map.put(MONEY_BANKLV, userSkin.getLevel());
                        map.put(MONEY_BANKADD, add);
                        map.put(MONEY_BANKNAME, userSkin.getSkinId());
                        objectGroup.add(map);
                    }
                }
            }
            action.build(MONEY_BANKLOOK, objectGroup);

            action.trace();
        } catch (Exception e) {
            DataAnalyticsMgr.getLogger().error(" error ", e);
        }

    }

}
